package com.weidft.dal.plan.dao.ibatis;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.weidft.dal.plan.dao.IAdaptionDAO;
import com.weidft.dal.plan.dataobject.AdaptionDO;

public class IBatisAdaptionDAO extends SqlMapClientDaoSupport implements
		IAdaptionDAO {

	public List<AdaptionDO> getAdaptionList() {
		return getSqlMapClientTemplate().queryForList(
				"PLAN_ADAPTION.listAllAdaption");
	}

	public List<AdaptionDO> getAdaptionList(AdaptionDO adaptionDO) {
		if (adaptionDO == null) {
			return getSqlMapClientTemplate().queryForList(
					"PLAN_ADAPTION.listAllAdaption", new AdaptionDO());
		} else {
			return getSqlMapClientTemplate().queryForList(
					"PLAN_ADAPTION.listAdaption", adaptionDO);
		}
	}

	@Override
	public AdaptionDO findAdaptionById(Integer id) {
		AdaptionDO record = new AdaptionDO();
		record.setId(id);
		List<AdaptionDO> udoList = getAdaptionList(record);
		if (udoList == null || udoList.size() == 0) {
			return null;
		}
		return udoList.get(0);
	}

	@Override
	public Integer insert(AdaptionDO record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"PLAN_ADAPTION.insert_Adaption", record);
		return (Integer) newKey;
	}

	@Override
	public int update(AdaptionDO record) {
		int rows = getSqlMapClientTemplate().update(
				"PLAN_ADAPTION.update_Adaption", record);
		return rows;
	}

	@Override
	public int deleteAdaptionById(Integer id) {
		int rows = getSqlMapClientTemplate().delete(
				"PLAN_ADAPTION.delete_Adaption", id);
		return rows;
	}

	// @Override
	// public Integer countAdaption(AdaptionDO adaptionDO) {
	// if (adaptionDO == null) {
	// return (Integer) getSqlMapClientTemplate().queryForObject(
	// "PLAN_ADAPTION.countAllAdaption", new AdaptionDO());
	// } else {
	// return (Integer) getSqlMapClientTemplate().queryForObject(
	// "PLAN_ADAPTION.countAdaption", adaptionDO);
	// }
	// }

}
